﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>会签</title>
    <!--
    1, 退回界面。
    2，需要 FK_Flow, FK_Node,WorkID, FID.
    3, 调用方法 HuiQian.htm?FK_Flow=001&FK_Node=103&WorkID=232&FID=23
    -->

    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/components-rounded.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/themes/default/style.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>

    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.cokie.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>

    <style type="text/css">
        body {
            background: transparent;
        }

            body div {
                text-align: left;
            }

        #Message {
            width: 100%;
        }

        #SelectEmp {
            position: relative;
            width: 400px;
            border-top: 0;
            display: none;
            margin-top: -7px; /*border: solid 2px #3175af;*/
        }

        .item {
            padding: 3px 5px;
            cursor: pointer;
            float: left;
            width: 190px;
            line-height: 20px;
            display: inline-block;
            background-color: #F7F7F7;
        }

        #next {
            float: left;
            position: relative;
            width: 600px;
        }

        .addbg {
            background: #CFCFCF;
        }
    </style>
    <script type="text/javascript">
        var param = {};
        var webUser;
        var huiQianType = GetQueryString("HuiQianType");
        var isFrameCross = GetQueryString("isFrameCross");
        $(function () {
            webUser = new WebUser();
            Help();

            //初始化页面移交页面
            param = {
                FK_Node: GetQueryString('FK_Node'),
                WorkID: GetQueryString('WorkID'),
                FID: GetQueryString('FID'),
                FK_Flow: GetQueryString("FK_Flow")
            };


            //初始化人员选择窗口
            var selectEmpModalHtml = '<div class="modal fade" id="selectEmpsModal">' +
                '<div class="modal-dialog">'
                + '<div class="modal-content" style="border-radius:0px;width:700px;">'
                + '<div class="modal-header">'
                + '<button type="button" class="close" style="color:white;opacity:1;" data-dismiss="modal" aria-hidden="true">&times;</button>'
                + '<h4 class="modal-title">选择会签人</h4>'
                + '</div>'
                + '<div class="modal-body">'
                + '<iframe style="width:100%;border:0px;height:400px;" id="iframeSelectEmpsForm" name="iframeSelectEmpsForm"></iframe>'
                + '</div>'
                + '</div><!-- /.modal-content -->'
                + '</div><!-- /.modal-dialog -->'
                + '</div>';

            $('body').append($(selectEmpModalHtml));

            var u = new WebUser();
            var dept = u.FK_Dept;
            var url = "SelectEmps.htm?IsSelectMore=1&FK_Dept=" + dept + "&FK_Node=" + GetQueryString("FK_Node") + "&s=" + Math.random();
            url = url.replace('=101&', '=10102&');

            $('#iframeSelectEmpsForm').attr('src', url);
            $('#Btn_SelectEmps').bind('click', function () { $('#selectEmpsModal').modal().show(); });
            $(".Msg").hide();

            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            var data = hand.DoMethodReturnString("HuiQian_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                CloseAll();
                return;
            }

            var data = JSON.parse(data);
            BindTable(data);

        });

        function BindTable(data) {
            //判断当前节点是否是第二组长
            var gwls = data.WF_GenerWorkList;
            var myGwl = data.My_GenerWorkList[0];
            var num = 0;
            for (var i = 0; i < gwls.length; i++) {

                var gwl = gwls[i];
                var zhuChiRen = GetPara(gwl.AtPara, "HuiQianZhuChiRen");
                var addLeader = GetPara(gwl.AtPara, "HuiQianType");
                if (gwl.FK_Emp != webUser.No) { //相同即为主持人
                    if (zhuChiRen != null && zhuChiRen != undefined && zhuChiRen != webUser.No)
                        continue;

                    //获取增加组长的信息
                    if (huiQianType != null && huiQianType != undefined && huiQianType == "AddLeader") {
                        if (addLeader == null || addLeader != "AddLeader")
                            continue;
                    } else {
                        if (addLeader != null && addLeader == "AddLeader")
                            continue;
                    }

                    if (GetPara(myGwl.AtPara, "HuiQianZhuChiRen") == gwl.FK_Emp)
                        continue;
                }

                var row = "";
                row += "<tr>";
                num++;
                row += "<td>" + num + "</td>";
                row += "<td>" + gwl.EmpName + "</td>";
                row += "<td  title='" + (gwl.DeptName || gwl.FK_DeptT) + "' >" + (gwl.DeptName || gwl.FK_DeptT) + "</td>";

                if (gwl.IsPass == -1) {
                    row += "<td>新增</td>";
                    row += "<td><a href=\"javascript:DeleteIt('" + gwl.FK_Emp + "'," + i + ");\" >移除</a></td>";
                }

                if (gwl.IsPass == 0) {
                    if (gwl.FK_Emp == webUser.No) {
                        row += "<td>主持人/未审批</td>";
                        row += "<td></td>";
                    }
                    else {
                        row += "<td>未审批</td>";
                        row += "<td><a href=\"javascript:DeleteIt('" + gwl.FK_Emp + "'," + i + ");\" >移除</a></td>";
                    }

                }



                //当前是主持人这个是协作模式处理
                if (gwl.IsPass == 100) {
                    row += "<td>主持人/未审批</td>";
                    row += "<td></td>";
                }
                if (gwl.IsPass == 1001) {
                    row += "<td>主持人/已审批:" + gwl.RDT + "</td>";
                    row += "<td></td>";
                }

                //当前是组长模式处理，并且是主持人
                if (gwl.IsPass == 90) {
                    row += "<td><font color=green>主持人（自己）/未审批</font></td>";
                    row += "<td></td>";
                }

                //当前自己
                if (gwl.IsPass == 99) {
                    row += "<td>主持人/未审批</td>";
                    row += "<td></td>";
                }

                //当前自己
                if (gwl.IsPass == 9901) {
                    row += "<td>主持人（您自己）/已审批</td>";
                    row += "<td></td>";
                }

                if (gwl.IsPass == 1) {
                    if (gwl.FK_Emp == webUser.No)
                        row += "<td>已审批:" + gwl.RDT + "</td>";
                    else
                        row += "<td>已审批:" + gwl.RDT + "</td>";
                    row += "<td></td>";
                }
                row += "</tr>";

                //$("#Table1 tr:last").after(row);
                $("#Table1 tbody").append(row);
            }
        }

        function DeleteIt(empNo, row) {

            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            hand.AddPara("FK_Emp", empNo);
            var data = hand.DoMethodReturnString("HuiQian_Delete");

            if (data.indexOf('err@') == 0 || data.indexOf('info@') == 0) {
                alert(data);
                return;
            }

            //delRow(row); //清空单个table tbody
            ClearTable();

            // 把返回的结果，重新绑定.
            var sas = JSON.parse(data);
            BindTable(sas);
            return;
        }

        //确定  执行会签操作
        function DoHuiQian(emps) {

            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            hand.AddPara("AddEmps", emps);
            hand.AddPara("HuiQianType", huiQianType);
            var data = hand.DoMethodReturnString("HuiQian_AddEmps");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            if (data.indexOf('info@') == 0) {
                $(".Msg").show();
                $(".Msg").html(data);
                return;
            }

            Reload();
        }

        //确定后，就弹出选择到达节点，选择接受人，填写审核意见窗口.
        function SaveAndClose() {
            var toNode = GetQueryString("ToNode");
            if (toNode == undefined || toNode == "undefined")
                toNode = "0";

            $("#Btn_HuiQian").attr("disabled", "disabled");
            $("#Btn_HuiQian").val("执行中...");
            $("#Btn_SelectEmps").attr("disabled", "disabled");
            var trs = $("tbody tr");
            var flag = true;
            if (trs.length >= 2) {
                $.each(trs, function (i, tr) {
                    if (tr.innerHTML.indexOf("新增") > 0) {

                        flag = false;
                        return;
                    };

                })
                if (flag) {
                    alert("表中会签人已审批，请选择新的会签人再发送！");
                    $("#Btn_HuiQian").attr("disabled", false);
                    $("#Btn_HuiQian").val("执行会签");
                    $("#Btn_SelectEmps").attr("disabled", false);
                    return;
                }

            }
            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            var data = hand.DoMethodReturnString("HuiQian_SaveAndClose");

            if (data.indexOf('url@') == 0) {
                data = data.replace('url@', '');
                SetHref(data);
                return;
            }

            //如果需要发送,就执行发送.
            if (data.indexOf('Send@') == 0) {
                SendIt();
                return;
            }

            //提示信息后关闭窗口.
            if (data.indexOf('close@') == 0) {

                alert(data.replace('close@', ''));
                if (isFrameCross == 0) {
                    if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                        window.parent.returnWorkWindowClose("");
                        window.parent.close();

                    } else {

                        $('body').append($('<div>' + "已取消操作" + '</div>'));

                        window.close();
                    }

                } else {
                    ChildrenPostMessage("", "returnWorkWindowClose");
                    window.parent.close();
                }


                return;
            }

            //提示信息.
            if (data.indexOf('info@') == 0) {

                alert(data.replace('info@', ''));

                $("#Btn_HuiQian").attr("disabled", false);
                $("#Btn_HuiQian").val("执行会签");
                $("#Btn_SelectEmps").attr("disabled", false);

                return;
            }

            alert(data);
            window.close();
            return;
        }

        //确定后，就弹出选择到达节点，选择接受人，填写审核意见窗口.
        function AddLeader() {
            $("#Btn_HuiQian").attr("disabled", "disabled");
            $("#Btn_HuiQian").val("执行中...");
            $("#Btn_SelectEmps").attr("disabled", "disabled");
            var trs = $("tbody tr");
            var flag = true;
            if (trs.length >= 2) {
                $.each(trs, function (i, tr) {
                    if (tr.innerHTML.indexOf("新增") > 0) {

                        flag = false;
                        return;
                    };

                })
                if (flag) {
                    alert("表中会签人已审批，请选择新的会签人再发送！");
                    $("#Btn_HuiQian").attr("disabled", false);
                    $("#Btn_HuiQian").val("执行会签");
                    $("#Btn_SelectEmps").attr("disabled", false);
                    return;
                }

            }
            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            var data = hand.DoMethodReturnString("HuiQian_AddLeader");
            alert(data);
            Reload();
            window.close();
            return;
        }

        //执行发送.
        function SendIt() {

            //执行数据初始化工作.
            var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            hand.AddUrlData();
            var data = hand.DoMethodReturnString("AccepterOfGener_Send");

            if (data.indexOf('err@') == 0) {
                $(".Msg").show();
                $(".Msg").html(data);
                return;
            }

            data = data.replace("'MyFlowInfo", "'../MyFlowInfo");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");

            data = data.replace("'WFRpt", "'../WFRpt");
            data = data.replace("'WFRpt", "'../WFRpt");

            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");

            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");


            data = data.replace('@', '<br/>@');
            data = data.replace(/@/g, '<br/>&nbsp;@');

            data = data.replace('@', '<br/>@');
            data += " <center><input type='button' value='    关    闭    ' onclick='CloseAll();'  /></center>";

            $("#btns").attr("display", "block");

            $(".Msg").show();
            $(".Msg").html(data);

            $("#labInfo").empty();
            $("#next").empty();

            //  display

            //隐藏table.
            document.getElementById("Table1").style.display = "none";
            document.getElementById("TB_Emps").style.display = "none";
            document.getElementById("Btn_SelectEmps").style.display = "none";

            //document.getElementById("Btn_AddEmps").style.display = "none";

            var ctrl = document.getElementById("Btn_Send");
            if (ctrl != null)
                ctrl.style.display = "none";

            ctrl = document.getElementById("labInfo");
            if (ctrl != null)
                ctrl.style.display = "none";

            ctrl = document.getElementById("Btn_Close");
            if (ctrl != null)
                ctrl.style.display = "none";
        }

        //取消移交
        function CloseAll() {
            if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                window.parent.returnWorkWindowClose();
            }
            window.close();
        }

        //设置选中的人员
        function selectEmpsWindowClose(data) {

            $('#selectEmpsModal').modal('hide');
            if (data == '取消') {
                return;
            }

            DoHuiQian(frames["iframeSelectEmpsForm"].window.returnVal.No);
            return;
            $('#TB_Emps').val(frames["iframeSelectEmpsForm"].window.returnVal.No);
        }

        //删除当前行
        function delRow(nowTr) {
            //$(nowTr).parents("tr").remove();
            $("#Table1 tbody tr:eq(" + nowTr + ")").remove();
        }

        //得到行对象
        function ClearTable() {

            var table = $("#Table1");
            var tbody = $("#Table1 tbody");
            var trArr = $("#Table1 tbody tr");
            tbody.empty();
        }

        $(function () {
            //人员选择
            $("#TB_Emps").bind('input propertychange', function () {
                if ($("#TB_Emps").val() == null || $("#TB_Emps").val() == "") {
                    $("#SelectEmp").hide().html("");
                    return;
                }

                //执行数据初始化工作.
                var hand = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
                hand.AddUrlData();
                hand.AddPara("TB_Emps", $("#TB_Emps").val());
                hand.AddPara("HuiQianType", huiQianType);
                var data = hand.DoMethodReturnString("HuiQian_SelectEmps");
                if (data.indexOf('err@') == 0) {
                    alert(data);
                    return;
                }

                data = JSON.parse(data);
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    html = html + "<div class='item' onclick='getCon(\"" + data[i].No + "\");' onmouseenter='getFocus(this)'>" + data[i].Name + "</div>";
                }
                $("#SelectEmp").show().html(html);

            });

            //如果是加主持人，变更按钮名称
            var huiQianType = GetQueryString("HuiQianType");
            if (huiQianType != null && huiQianType != undefined && huiQianType == "AddLeader") {
                $("#Btn_HuiQian").html("增加主持人");
                $("#Btn_HuiQian").attr("onclick", "AddLeader()");
            }


        });

        function selectAdd(No) {
            DoHuiQian(No);
        }

        //鼠标事件
        function getFocus(obj) {
            $(".item").removeClass("addbg");
            $(obj).addClass("addbg");
        }

        //选择下拉数据
        function getCon(no) {

            $("#TB_Emps").val('');

            DoHuiQian(no);

            $("#SelectEmp").hide().html("");
        }

        function Help() {
            $("#HelpInfo").toggle();
        }
    </script>
</head>
<body style="margin:10px;">
    <table id="Table1" style="width: 98%; margin:5px;">
        <thead>
            <tr id='title'>
                <th>#</th>
                <th>姓名</th>
                <th> 所在部门 </th>
                <th> 状态 </th>
                <th> 操作 </th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <br />
    <div>
        <div id="labInfo">
            输入关键字: <input type="text" id="TB_Emps" title="查张三,您可输入: zs或zhangs或zhangsan"
                          placeholder="查张三,您可输入:zs或zhangs或zhangsan" name="TB_Emps" value='' style="width: 300px;" />
            <input type="button" id="Btn_SelectEmps" value='选人' /><a href="javascript:Help()">帮助</a>
            <div id="SelectEmp">
            </div>
            <br />
            <div id="next">

                <!--<img src="../Img/Multiplayer.png" onclick="SaveAndClose();" style="width:27px;" />-->

                <button id="Btn_HuiQian" class="btn-info" onclick="SaveAndClose();">执行会签</button>
                <span style="color:red"></span>
                <div id="HelpInfo" style="">
                    <ul>
                        <li> 当前节点工作的处理人为会签主持人，可增加其他人员作为会签人，提供意见。</li>
                        <li> 点击“保存会签人列表并关闭”按钮后，可将工作发送至列表中除主持人以外的所有会签人的待办，在所有会签人都处理完成后，主持人才可向下一步发送工作。</li>
                        <li> 若会签人长时间未处理该工作，或会签主持人不再需要该人提供处理意见，在会签人列表中状态为“未审批”的情况下，可以由会签主持人移除。</li>
                        <li> 可以使用人员名称拼音，支持全拼和简拼。</li>
                        <li> 例如:查找耿润华您可以输入: grh 或者 gengrh 或者 gengrunhua</li>
                        <li> 支持单位名称，例如：耿润华/集团信息中心， 可以输入为 grh/jtxxzx</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="Msg" style="float: left;">
            <img src='../Img/loading.gif' alt="" />页面数据正在加载中，请稍候......
        </div>
    </div>
    <br />

</body>
</html>
